import { getUserInfo } from '@/libraries/apis/user';

const state = {
    userInfo: {
        avatar: undefined,
        nickname: undefined,
        openid: undefined,
        phone: undefined
    },
    deviceInfo: {}
};
const mutations = {
    SET_DEVICE_INFO(state, deviceInfo) {
        state.deviceInfo = deviceInfo;
    },
    SET_USERINFO(state, userInfo) {
        state.userInfo = userInfo;
    }
};

const actions = {
    async gatherDeviceInfo({ commit }) {
        uni.getSystemInfo({
            success(result) {
                commit('SET_DEVICE_INFO', result);
            }
        });
    },
    async updateUserInfo({ commit }) {
        const userInfo = await getUserInfo();
        commit('SET_USERINFO', userInfo);
    }
};

module.exports = {
    namespaced: true,
    state,
    mutations,
    actions
};
